{include file="public/header" /}
<body class="gray-bg">
<div class="wrapper wrapper-content">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>编辑章节</h5>
                </div>
                <div class="ibox-content layui-form">
                    <div class="layui-row layui-col-space10 layui-form-item">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">章节名称：</label>
                            <div class="layui-input-block">
                                <input type="text" name="c_section_name" lay-verify="required" placeholder="章节名称" class="layui-input" value="{$section.c_section_name}">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">章节排序：</label>
                            <div class="layui-input-block">
                                <input type="text" name="c_section_sort" lay-verify="required" placeholder="章节排序" value="{$section.c_section_sort}" class="layui-input" oninput="value=value.replace(/^(0+)|[^\d]/g,'')">
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8 form-group">
                            <label class="layui-form-label">状态：</label>
                            <div class="layui-input-block">
                                <input type="radio" name="c_section_status" value="1" class="layui-input" title="上架" {$section.c_section_status == 1 ? 'checked' : ''} />
                                <input type="radio" name="c_section_status" value="2" class="layui-input" title="下架" {$section.c_section_status == 2 ? 'checked' : ''} />
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <label class="layui-form-label">音频：</label>
                            <input type="hidden" name="c_section_url" id="lay-music" lay-verify="music" value="{$section.c_section_url}">
                            <div class="layui-input-block">
                                <div id="lay-music-upload">上传音频</div>
                                <blockquote class="layui-elem-quote layui-quote-nm" style="margin-top: 10px;">
                                    预览音频：
                                    <div class="layui-upload-list" id="lay-music-list">
                                        <audio controls src="{$section.c_section_url}"></audio>
                                    </div>
                                </blockquote>
                            </div>
                        </div>

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md10">
                            <label class="layui-form-label">章节详情：</label>
                            <div class="layui-input-block" id="LAY_editor" lay-verify="editor">
                                <p>{$section.c_section_detail}</p>
                            </div>
                        </div>

                        <input type="hidden" value="{$c_section_id}" name="c_section_id">
                        <input type="hidden" value="{$class_video_audio}" name="class_video_audio">

                        <div class="layui-form-item layui-col-md-offset1 layui-col-md8">
                            <div class="layui-input-block">
                                <button class="layui-btn" lay-submit="" lay-filter="component-form-element">保存
                                </button>
                                <!--<button class="layui-btn layui-btn-primary" onclick="history.go(-1)">关闭</button>-->
                            </div>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
{include file="public/footer" /}
<script>
    wk.uploadMusic({size:100,type:'mp3',url:"{:url('Upload/upload')}",domain:"{:config('qiniu.domain')}"});//音频上传
    var editor = wk.wang({elem:'#LAY_editor'});
    layui.use(['form','upload','layedit'], function() {
        var form = layui.form;
        form.verify({
            editor:function(value,item){
                if(editor.txt.html() == '<p><br></p>'){
                    return '请填写内容';
                }
            }
        });
        form.on('submit(component-form-element)', function (data) {
            data.field.c_section_detail = editor.txt.html();
//            $('.layui-btn').addClass('layui-disabled').attr('disabled','disabled');
            $.ajax({
                url:"{:url('sectionEdit')}",
                type:'post',
                dataType:'json',
                data:data.field,
                success:function(res){
                    if (res.code == 200) {
                        layer.msg(res.msg,{icon:1,time:1500,shade:0.1},function(index){
                            wk.layer_close();
                        });
                    } else {
                        wk.error(res.msg,'','$(".layui-btn").removeClass(\'layui-disabled\').removeAttr(\'disabled\');');
                    }
                }
            })
        });
    });

</script>
</body>
</html>
